﻿// <copyright file="ViewModel.cs" company="Microsoft Corporation">
// Copyright (c) 2011 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2011-02-12</date>
// <summary>ViewModel class</summary>

namespace NYTMovieReviews
{
    using System.Collections.ObjectModel;
    using NYTimes;
    using NYTimes.Data;

    public class MoviePivot
    {
        /// <summary>
        /// Gets or sets the pivot's display name
        /// </summary>
        public string DisplayName { get; set; }

        /// <summary>
        /// Gets or sets the reviews
        /// </summary>
        public MovieReviewsByKeyword Reviews { get; set; }
    }

    /// <summary>
    /// Represents the view model for the Movie Reviews application
    /// </summary>
    public class ViewModel
    {
        #region Fields
        /// <summary>
        /// The New York Times Movie Reviews API Key
        /// </summary>
        private const string ApiKey = "63b54eadfaebad00123f8b27a5090b49:17:57351476";
        #endregion
        
        /// <summary>
        /// Initializes a new instance of the ViewModel class
        /// </summary>
        public ViewModel()
        {
            this.Pivots = new ObservableCollection<MoviePivot>();

            this.Pivots.Add(new MoviePivot
            {
                DisplayName = "recent",
                Reviews = new MovieReviewsByKeyword 
                {
                    ApiKey = ApiKey,
                    ResultsToGet = 20,
                }
            });

            this.Pivots.Add(new MoviePivot
            {
                DisplayName = "published",
                Reviews = new MovieReviewsByKeyword
                {
                    ApiKey = ApiKey,
                    Order = MovieReviewOrder.PublicationDate,
                    ResultsToGet = 20,
                }
            });

            this.Pivots.Add(new MoviePivot
            {
                DisplayName = "opening",
                Reviews = new MovieReviewsByKeyword
                {
                    ApiKey = ApiKey,
                    Order = MovieReviewOrder.OpeningDate,
                    ResultsToGet = 20,
                }
            });

            this.Pivots.Add(new MoviePivot
            {
                DisplayName = "DVD",
                Reviews = new MovieReviewsByKeyword
                {
                    ApiKey = ApiKey,
                    Order = MovieReviewOrder.DVDReleaseDate,
                    ResultsToGet = 20,
                }
            });
        }
        
        public int ResultsToGet
        {
            get
            {
                return this.Pivots[0].Reviews.ResultsToGet;
            }
            
            set
            {
                foreach (var pivot in this.Pivots)
                {
                    pivot.Reviews.ResultsToGet = value;
                }
            }
        }

        public string Query
        {
            get
            {
                return this.Pivots[0].Reviews.Query;
            }

            set
            {
                foreach (var pivot in this.Pivots)
                {
                    pivot.Reviews.Query = value;
                }
            }
        }

        public ObservableCollection<MoviePivot> Pivots { get; private set; }

    }
}
